<?php
/*
 * index.action.php     Zhuayi 微博模块
 *
 * @copyright    (C) 2005 - 2010  zhuayi
 * @licenes      http://www.zhuayi.net
 * @lastmodify   2010-10-28
 * @author       zhuayi
 * @QQ			 2179942
 */
class weibo_action extends zhuayi
{

	/* 构造函数 */
	function __construct()
	{
		parent::__construct();
		
		/* 验证登录 */
		$this->user = member_action::verify();
		
		$this->db = parent::db();
		
		$this->account = cookie::ret_cookie('account');
		
		
	}
	
	
	/* 发布框  */
	function text()
	{
		/* 随机时间 */
		for ($i=1;$i<=10;$i++)
		{
			$rand_time[$i] = $i.'小时之内';
		}
		
		/* 默认当前时间 */
		$dtime = date('Y-m-d H:i:s',time()+120);

		require $this->load_tpl('weibo_text');
	}
	
	
	/* 上传图片 */
	function upload()
	{
		require $this->load_tpl('weibo_upload');
	}
	
	/* 图片写入 */
	function upload_info()
	{
		/* 载入文件上传类 */
		$upload = $this->load_class('upload',true);
		
		$litpic = $upload->copy($_FILES['file1'],'','weibo',time());
		echo $litpic;
	}
	
	/* 删除图片 */
	function del_pic()
	{
		unlink(str_replace($this->weburl,ZHUAYI_ROOT,$_GET['file']));
		echo '1';
	}
	
	/* 发布文博 */
	function info()
	{
		if ($_POST['timing'] == '1')
		{
			/* 开始时间 */
			$starttime = time()+120;
			
			/* 结束时间 */
			if (!empty($_POST['rand_time']))
			{
				$_POST['rantime'] = $_POST['rand_time'].'小时之内';
				$endtime = time()+$_POST['rand_time']*3600;
			}
			else
			{
				$_POST['rantime'] = $_POST['dtime'];
				
				$endtime = strtotime($_POST['dtime']);
				if (($endtime - $starttime) < 120)
				{
					$endtime = $starttime+120;
				}
			}
			$_POST['mid'] = $this->user['id'];
			/* 写入微博任务 */
			$aid = timing_modle::weibo_info($_POST);
			foreach ($_POST['userid'] as $val)
			{
				$timing = array();
				$timing['url'] .= '/timing/weibo_save/{aid}/'.$aid.'/{tid}';
				$timing['aid'] .= $val;
				$timing['dtime'] .= rand($starttime,$endtime);
				$timing['type'] = 'weibo';
				$timing['tid'] = $aid;
				$timing['mid'] = $_POST['mid'];
				timing_modle::info($timing);
			}
			exit('2');
		}
		
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);
		
		
		$val = $app->weibo_info($_POST['status'],$_POST['pic']);
	
		require $this->load_tpl('weibo_'.$this->account['api'].'repost');
	}
	
	/* 微博删除 */
	function delete($id)
	{
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);
		
		
		$reset = $app->delete($id);
		
		
		exit('1');
	}
	
	/* 微博列表 */
	function lists($feature)
	{
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);
		
		
		$list = $app->weibo_list(array('feature'=>$feature));
		
		require $this->load_tpl('weibo_'.$this->account['api'].'list');
	}
	
	/* 转发一条微博 */
	function repost()
	{
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);
		$ip = $this->load_fun('get_ip');
	
		$val = $app->weibo_repost($_POST);
		
		if ($val['error_code'] == '-1')
		{
			exit('-1');
		}
		
		require $this->load_tpl('weibo_'.$this->account['api'].'repost');
	}
	
	/* 获得评论列表 */
	function comment_list($id)
	{
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);
		
		$val = $app->comments_list(array('id'=>$id,'count'=>20));
		
		exit(json_encode($val));
	}
	
	/* 评论一条微博 */
	function comment()
	{
	
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);
		
		if ($_POST['is_comment'] == 1)
		{
			$_POST['status'] = $_POST['comment'];
			$val = $app->weibo_repost($_POST);
		}
		
		$val = $app->comment($_POST);
		
		if ($val['error_code'] == '-1')
		{
			exit('-1');
		}
		
		exit(json_encode($val));
		
	}
	
	/* 获取转发数和评论数 */
	function status_counts($ids)
	{
		$ids = urldecode($ids);
		
		
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);
		
		$reset = $app->status_counts($ids);
		
		echo json_encode($reset);
	}
	
	/* @我的列表 */
	function atme()
	{
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);
		
		
		$list = $app->atme(array('feature'=>$feature));
		
		
		require $this->load_tpl('weibo_'.$this->account['api'].'list');
	}
	
	/* 评论列表 */
	function comment_lists($act)
	{
		if ($this->account['api'] =='sina')
		{

			/* 组合APP */
			$app = $this->account['api'].'_action';
			
			$app = new $app($this->account['token']);

			$list = $app->comment_lists($act);
		}
		
		require $this->load_tpl('weibo_'.'sina.comment.lists');
	}
	
	/* 删除评论 */
	function comment_del()
	{
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);

		$list = $app->comment_del($_POST['id']);

		echo '1';
	}
	
	/* 回复一条评论 */
	function reply()
	{
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);

		
		
		/* 转发 */
		if ($_POST['is_comment'] == '1')
		{
			$app->weibo_repost(array('id'=>$_POST['id'],'status'=>$_POST['comment'],'is_comment'=>3));
		}
		else
		{
			$list = $app->comment_reply($_POST);
		}
		
	}
	
	/* 我的收藏 */
	function favorites()
	{
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);
		
		$list = $app->favorites();
		
		$act = '1';
		
		require $this->load_tpl('weibo_'.$this->account['api'].'list');
	}
	
	/* 添加收藏 */
	function favorites_add()
	{
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);
		
		$list = $app->add_favorites($_POST['id']);
		
		
		echo '1';
	}
	
	/* 删除收藏 */
	function favorites_del()
	{
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);
		
		$list = $app->del_favorites($_POST['id']);
		
		
		echo '1';
	}
	
	/* 我的微博 */
	function my_weibo()
	{
		/* 组合APP */
		$app = $this->account['api'].'_action';
		
		$app = new $app($this->account['token']);
		
		$list = $app->my_weibo($_POST['id']);
		
		require $this->load_tpl('weibo_'.$this->account['api'].'list');
	}



}
?>